package Text54;

import java.util.*;

public class Main {
    static int N = 1010, M = 510;
    static int[][] f = new int[N][M];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int v1 = in.nextInt();
        int v2 = in.nextInt();
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            for (int j = v1; j >= a; j--) {
                for (int k = v2 - 1; k >= b; k--) {
                    f[j][k] = Math.max(f[j][k], f[j - a][k - b] + 1);
                }
            }
        }
        int k = v2 - 1;
        while (k > 0 && f[v1][k - 1] == f[v1][k]) {
            k--;
        }
        System.out.println(f[v1][v2 - 1] + " " + (v2 - k));
    }
}
